<template>
	<view class="mycollection_wp">
		<view class="m_nav">
			<view :class="{m_active:active==0}" @click="navTap(0)">商品收藏</view>
			<view :class="{m_active:active==1}" @click="navTap(1)">店铺收藏</view>
		</view>
		<view class="m_list">
			<checkbox-group class="m_s_list" v-if="active==0" @change="shopcheckchange">
				<view class="m_s_item" v-for="item in list" :key="item.id">
					<checkbox v-if="isdelete" style="transform:scale(0.9)" :value="item.id" :checked="item.checked" />
					<view class="m_s_item m_s_item1" @click="$navTo('../product/product?id='+item.goodsid)">
						<image :src="item.thumb"></image>
						<view class="m_s_i_info">
							<view class="m_s_i_title">{{item.title}}</view>
							<view class="m_s_i_money">
								<text>{{item.marketprice}}</text>
								<!-- <text>米券</text> -->
							</view>
							<view class="m_s_i_oldmoney">门市价：￥{{item.productprice}}</view>
						</view>
					</view>
				</view>
			</checkbox-group>
			
			<checkbox-group class="m_s_list" @change="shopcheckchange" v-if="active==1">
				<view class="m_d_item" v-for="item in list" :key="item.id">
					<checkbox v-if="isdelete" style="transform:scale(0.9)" :value="item.id" :checked="item.checked" />
					<view class="m_d_item m_d_item1" @click="$navTo('/pages/shoplist/shopgoods?id='+item.uid)">
						<image :src="item.logo"></image>
						<view class="m_d_i_title">
							<view>{{item.title}}</view>
							<view style="color: #666;font-size: 22upx;">{{item.introduce}}</view>
						</view>
					</view>
					
				</view>
			</checkbox-group>
			
		</view>
		
		<view class="m_delete" v-if="!isdelete" @click="isdelete=true">删除</view>
		<view class="m_checkbox" v-if="isdelete">
			<checkbox-group @change="checkchange" style="flex: 1;">
			<label>
				<checkbox value="check" style="transform:scale(0.8)" />全选
			</label>
			</checkbox-group>
			<view class="m_c_button m_c_button1" @click="isdelete=false">取消</view>
			<view class="m_c_button" @click="deleteshop">删除</view>
		</view>
		
		<view class="m_loading" v-if="isloading">
			<image src="../../static/business/loading.gif" mode=""></image>
		</view>
		<view class="m_loading" v-if="iskong">没有更多了~</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active:0,
				
				isdelete:false,
				
				list: [],
				shopcheck:[],
				
				page: 0,
				type:0,
				
				ids: [],
				goodsid: [],
				
				isloading:false,
				empty: false,
				iskong:false,
			}
		},
		onReachBottom() {
			this.getlist();
		},
		onLoad(option) {
			this.getlist();
		},
		methods: {
			deleteshop(){
				var ids=this.shopcheck.join(',');
				uni.showLoading({title:'删除中'});
				this.$axios('favorite/remove', "POST", 'shop', {ids}).then(res=>{
					uni.hideLoading();
					if(res.data.code==200){
						this.$api.msg('删除成功');
						setTimeout(()=>{
							this.isdelete=false;
							this.$navRed('../userservice/mycollection');
						},1000)
					}else{
						this.$api.msg(res.data.data)
					}
				})
			},
			navTap(v){
				if(this.active==v) return ;
				this.isdelete=false;
				this.shopcheck=[];
				this.active=v;
				this.page=0;
				this.type=v;
				this.list =[];
				this.getlist();
			},
			
			getlist(){
				this.page+=1;
				this.isloading=true;
				this.$axios('favorite/display', "POST", 'shop', {
					page: this.page,
					type:this.type
				}).then(res => {
					this.isloading=false;
					if (res.data.code == 200) {
						res.data.data.list.map(item=>{
							var obj=JSON.parse(JSON.stringify(item));
							obj.checked=false,
							this.list.push(obj);
						})
						this.iskong=res.data.data.list.length<=0?true:false;
						this.$nextTick(function() {
							this.empty = this.list.length == 0 ? true : false;
						})
					}
				})
			},
			shopcheckchange(e){
				this.shopcheck=e.detail.value;
			},
			checkchange(e){
				this.shopcheck=[];
				this.list.map(item=>{
					if(e.detail.value.length){
						this.shopcheck.push(item.id);
						item.checked=true;
					}else{
						item.checked=false;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		color: $font-color-dark;
		padding-bottom: 130upx;
	}
	.m_nav{
		background: #fff;
		border-bottom: 1px hsl(0,0%,87%) solid;
		display: flex;
		align-items: center;
		line-height: 100upx;
		height: 100upx;
		font-size: $font-base;
		position: fixed;
		width: 100%;
		z-index: 500;
	}
	.m_nav view{
		flex: 1;
		text-align: center;
		position: relative;
	}
	.m_active{
		color: $base-color;
	}
	.m_active:after{
		border-bottom: 3px $base-color solid;
		content: '';
		position: absolute;
		bottom: 10upx;
		left: 50%;
		transform: translateX(-50%);
		width: 50upx;
	}
	.m_list{
		padding-top: 100upx;
	}
	.m_s_item,.m_d_item{
		padding: 20upx;
		border-bottom: 1px hsl(0,0%,87%) solid;
		display: flex;
		align-items: center;
	}
	.m_s_item image{
		border-radius: 10upx;
		height: 130upx;
		width: 130upx;
	}
	.m_s_item1{
		border: none;
	}
	.m_d_item image{
		border-radius: 10upx;
		height: 90upx;
		width: 90upx;
	}
	.m_d_i_title{
		flex: 1;
		padding-left: 15upx;
		line-height: 30upx;
		overflow: hidden;
	}
	.m_d_item1{
		border: none;
		display: flex;
		align-items: center;
	}
	.m_s_i_info{
		flex: 1;
		padding-left: 15upx;
		line-height: 30upx;
		font-size: $font-sm;
	}
	.m_s_i_title{
		height: 60upx;
		overflow: hidden;
	}
	.m_s_i_money{
		padding: 5upx 0;
		color: $base-color;
	}
	.m_s_i_money text:nth-of-type(2){
		font-size: 20upx;
	}
	.m_s_i_oldmoney{
		font-size: $font-sm;
		color: $font-color-light;
	}
	.m_delete{
		background: $base-color;
		border-radius: 40upx;
		color: #fff;
		line-height: 70upx;
		position: fixed;
		bottom: 30upx;
		left: 3%;
		text-align: center;
		width: 94%;
	}
	.m_checkbox{
		background-color: #fff;
		border-top: 1px hsl(0,0%,87%) solid;
		display: flex;
		align-items: center;
		padding: 0 20upx;
		position: fixed;
		bottom: 0;
		line-height: 100upx;
		width: 100%;
		
	}
	.m_c_button{
		background: linear-gradient(to right,#f03201, #ff7101);
		border-radius: 40upx;
		color: #fff;
		line-height: 50upx;
		width: 130upx;
		letter-spacing: 2px;
		text-align: center;
	}
	.m_c_button1{
		background: #D6D6D6;
		color: $font-color-dark;
		margin-right: 20upx;
	}
	.m_loading{
		text-align: center;
		padding: 30upx;
		color: #0062CC;
	}
	.m_loading image{
		height: 60upx;
		width: 60upx;
	}
	.m_empty{
		position: fixed;
		top: 0;
		width: 100%;
		height: 100%;
	}
	.m_e_name{
		color: $font-color-light;
		position: absolute;
		top: 300upx;
		left: 50%;
		transform: translateX(-50%);
		text-align: center;
	}
	.m_e_name image{
		width: 180upx;
	}
</style>
